// 导出一个axios的实例  而且这个实例要有请求拦截器 响应拦截器
import axios from 'axios'
import store from '@/store'
// import t from './android'
// 创建一个axios的实例
const service = axios.create({
    // 设置基地址
    timeout: 10000,
})
service.defaults.headers["Content-Type"] = "application/json";

// 请求拦截器
service.interceptors.request.use(
    (config) => {
        //添加请求头
        const a = 'GHTQZ5OZ973101ac048c021c4079118c2b7b7ec6c1dbbdbc4a6579db9f25ccf911bcc8207e34aef72bf0b3a0b0e15178f9ee3fa06899a02bc9f883d1f104d7138809c8bcfaf3fd33323e971be90c47100e30a01d26ab54301d0c044f78680365344b43126d64cf71f09805e012b1c0f6e1fa4991'
            // console.log('token', t())
        config.headers.Token = a

        // 判断用户是否登录添加token
        const token = store.state.user.userInfo.token
        if (token) {
            config.headers.Auth = token
        }
        store.commit('showLoading')
        return config
    },
    (error) => {
        store.commit('showLoading')
        return Promise.reject(error)
    }

)

// 响应拦截器
service.interceptors.response.use(
    (response) => {
        store.commit('hideLoading')
        return response
    },
    (error) => {
        store.commit('hideLoading')
        return Promise.reject(error)
    }
)

export default service // 导出axios实例